package com.zhb.lkd.controller;


import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.exception.BusinessException;
import com.zhb.lkd.pojos.entity.Node;
import com.zhb.lkd.pojos.entity.VmType;
import com.zhb.lkd.service.INodeService;
import com.zhb.lkd.service.IVmTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 售货机类型表 前端控制器
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@RestController
@RequestMapping("/api/vm-service/vmType")
@Slf4j
@Api(tags = "售货机类型相关接口")
public class VmTypeController {
    @Resource
    private IVmTypeService typeService;

    @GetMapping("/search")
    @ApiOperation("设备搜索")
    public ResponseResult search(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize, String name) {
        log.info("设备搜索{}", name);
        PageResponse pageResponse = typeService.search(pageIndex, pageSize, name);
        return ResponseResult.ok(pageResponse);
    }


    @PostMapping("")
    @ApiOperation("新增设备类型")
    public ResponseResult create(@RequestBody VmType vmType) {
        log.info("新增设备类型{}", vmType);
        typeService.create(vmType);
        return ResponseResult.ok();
    }


    @PutMapping()
    @ApiOperation("修改设备类型")
    public ResponseResult updateById(@RequestBody VmType vmType) {
        log.info("修改设备类型{}", vmType);
        if (vmType.getTypeId()==0||vmType.getTypeId()==null){
            throw new BusinessException(500,"设备类型id不能为空");
        }
        boolean b = typeService.updateById(vmType);
        return ResponseResult.ok();
    }


    @DeleteMapping("/{typeId}")
    @ApiOperation("删除合作商")
    public ResponseResult deleteById(@PathVariable String typeId) {
        log.info("删除合作商{}", typeId);
        typeService.deleteById(typeId);
        return ResponseResult.ok();
    }
}
